package cn.xo68.ide.plugin.common.log;

import cn.xo68.ide.plugin.common.component.ToolSuiteLogOutput;
import com.intellij.openapi.application.ApplicationManager;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 日志追加者
 * @author wuxie
 */
public class ToolSuiteLogAppender extends ConsoleAppender {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    public ToolSuiteLogAppender(Layout layout) {
        super(layout);
    }

    @Override
    public void append(LoggingEvent event) {
        try {
            ToolSuiteLogOutput toolSuiteLogOutput= ApplicationManager.getApplication().getComponent(ToolSuiteLogOutput.class);
            toolSuiteLogOutput.log(event, this.layout.format(event));
        }catch (AssertionError error){
            // logger.error("",error);
        }

    }
}
